package com.wnxy.controller;

import com.wnxy.config.SubmitOnTime;
import com.wnxy.entity.User;
import com.wnxy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    // 幂等注解，保证在5秒内不能重复提交表单执行添加； 添加数据后，要等5秒才能再次添加
    @SubmitOnTime(expireTime = 5)
    @PostMapping
    public String save(@RequestBody User user){
        userService.save(user);
        return "ok";
    }

    @GetMapping("/test")
    public String test(){
        return "测试服务器正常";
    }

    // 模拟CPU过高
    @GetMapping("/query")
    public String testQuery(){
        return userService.testQuery();
    }

    // 模拟死锁问题
    @GetMapping("/dealData")
    public String testDealData(){
        return userService.testDealData();
    }
}
